package com.zhang.sparksql_2


import org.apache.spark.sql.{DataFrame, SparkSession}

/**
 * @title:
 * @author: zhang
 * @date: 2022/2/19 09:36 
 */
object SparkSQL02_DataFrame {

  def main(args: Array[String]): Unit = {

    //todo 获取执行环境
    val spark: SparkSession = SparkSession
      .builder()
      .master("local[*]")
      .appName("DataFrame")
      .getOrCreate()

    import spark.implicits._

    val df: DataFrame = spark.read.json("data/user.json")
    //todo --------------------sql-------------------
    //df.show
    //df.createTempView("user")

    //spark.sql("select * from user").show()

    // todo -----------------------DSL----------------------
    df.select("id").show()
    df.select("*").show()
    df.select($"age"+1).show()

    // todo 关闭环境
    spark.stop()

  }
}
